local SequencePlayer = class("SequencePlayer",function() return display.newNode() end)

function SequencePlayer.create()
	local player = SequencePlayer.new()
	return player
end

function SequencePlayer:ctor()
	self.seq = {}
	-- self:enableNodeEvents()
	self:schedule(handler(self,SequencePlayer.tick),0.1)
end

function SequencePlayer:onCleanup()
	for _,node in pairs(self.seq) do
		if node then
			node:release()
		end
	end
	self.seq={}
end

function SequencePlayer:push(node)
	table.insert(self.seq,node)
	node:retain()
	node:pause()

	--tick immediately
	-- if #self.seq == 1 then
	-- 	self:tick()
	-- end
end

function SequencePlayer:tick()
	if #self.seq <= 0 then
		return 
	end

	local node = self.seq[1]
	self:addChild(node)
	node:resume()

	table.remove(self.seq,1)
	node:release()
end

-- function SequencePlayer:updateChildrenPos(posX, posY)
-- 	for i,node in ipairs(self:getChildren()) do
--         node:setPosition(posX, posY)
--     end 
-- end

return SequencePlayer